package com.example.javaairportflightanalysis.comparator;

import java.util.Comparator;
import java.util.function.Function;

/**
 * 比较器，用于比较status，以便于可以排序
 */
public class StatusComparator<T> implements Comparator<T> {
    private final Function<T, Integer> statusExtractor;

    public StatusComparator(Function<T, Integer> statusExtractor) {
        this.statusExtractor = statusExtractor;
    }


    @Override
    public int compare(T obj1, T obj2) {
        // 提取obj1和obj2的status值进行比较
        int status1 = statusExtractor.apply(obj1);
        int status2 = statusExtractor.apply(obj2);
        return Integer.compare(status1, status2);
    }
}
